<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';

$basic=$this->plugin_setting('basic');
$return['banner']=$basic['image'];
$return['basic']=$basic;
//我的足迹
if($_RQ['op']=='main'){
	$zujilist=pdo_getall('jy_vote_looklist',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'','createtime desc');
	$list=array();
	if($zujilist){
		foreach($zujilist as &$item){
			$opus=pdo_get('jy_vote_opus',array('id'=>$item['oid'],'uniacid'=>$_SESSION['uniacid']));
			if(empty($opus)){
				pdo_delete('jy_vote_looklist',array('uniacid'=>$_SESSION['uniacid'],'oid'=>$item['oid']));
			}else{
				array_push($list,$opus);
			}
		}
	}
	if($list){
		$sum=count($list);
		foreach($list as &$item){
			$reply=pdo_get('jy_vote_reply',array('id'=>$item['rid'],'uniacid'=>$_SESSION['uniacid']));
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$item['reply']=$reply;
			$item['opus_images']=json_decode($item['opus_images'],true);
			$item['picsnum']=count($item['opus_images']);
			
		}
	}
	$return['list']=$list;
	$return['sum']=$sum;
	exi($return);

}
if($_RQ['op']=='getlist'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
	}
	if($_RQ['keyword']){
		if(is_numeric($_RQ['keyword'])){
			$params['id']=intval($_RQ['keyword']);
			$return['params']['id']=intval($_RQ['keyword']);
			$list=pdo_getall('jy_vote_opus',$params,$fields,'','createtime desc');
		}else{
			$return['params']['title']=$_RQ['keyword'];
			$list=pdo_getall('jy_vote_opus',$params,$fields,'','likes desc, id desc');
			if($list){
				$sum=count($list);
				foreach($list as $k=>&$v){
					$title=base64_decode($v['title']);
					
					if(!strexists($title,$_RQ['keyword'])){
						
						unset($list[$k]);
					}
					
				}
			}
			$list=array_values($list);
		}
	}else{
			$pindex = max(1, intval($_RQ['page']));
			$psize = 10;
			$list=pdo_getslice('jy_vote_opus',$params,array($pindex,$psize),$total,$fields,'','id desc');
	}

	if($list){
		$sum=count($list);
		foreach($list as &$item){
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$item['opus_images']=json_decode($item['opus_images'],true);
			$item['picsnum']=count($item['opus_images']);
			//$item['statustitle']=$item['status']==0?'待审核':$item['status']==1?'审核通过':'不通过';
			if($item['status']==0){
				$item['statustitle']='审核中';
			}elseif($item['status']==1){
				$item['statustitle']='审核通过';
			}else{
				$item['statustitle']='不通过';
			}
		}
	}
	else{
		$sum=0;
	}
	$return['list']=$list;
	exi($return);
}